using System;
using System.Collections.Generic;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using ExpressionCalculator;
using Infragistics.Win.UltraWinGrid;
using PluginFrame;

namespace ExperimentRuleEditor
{
	public class RuleEditorService : IPlugin, IProvideService, IRuleEditorService
	{
		private IApplication mApplication;

		private string mName = "";

		private string mDescription = "";

		protected ResourceManager mResourceManager;

		protected IConfigurationService mConfigurationService;

		private Calculator mCalculator = new Calculator();

		private int mIndex;

		private Rule_Editor m_LRuleEditor;

		public int Index
		{
			get
			{
				return mIndex;
			}
			set
			{
				mIndex = value;
			}
		}

		public IApplication Application
		{
			get
			{
				return mApplication;
			}
			set
			{
				mApplication = value;
			}
		}

		public string Name
		{
			get
			{
				return mName;
			}
			set
			{
				mName = value;
			}
		}

		public string Description
		{
			get
			{
				return mDescription;
			}
			set
			{
				mDescription = value;
			}
		}

		public event EventHandler<EventArgs> PluginEvent;

		public void Execute(object[] context)
		{
		}

		public void UnLoad()
		{
		}

		public object ProvideService()
		{
			return null;
		}

		public void Load()
		{
			if (mApplication != null)
			{
				mApplication.AddService(mName, this);
				mResourceManager = ResourceManager.CreateFileBasedResourceManager("ExperimentRuleEditor", mApplication.GetAssemblyPath() + "Resource\\" + GetType().Namespace + "\\", null);
				mConfigurationService = (IConfigurationService)mApplication.GetService("ConfigurationService");
			}
		}

		public void DisplayRuleForm(Panel mPanel, bool isLocked)
		{
			IRuleItem mRuleItem = new RuleItem();
			m_LRuleEditor = new Rule_Editor(mApplication, mRuleItem, isLocked);
			m_LRuleEditor.TopLevel = false;
			m_LRuleEditor.Dock = DockStyle.Fill;
			m_LRuleEditor.FormBorderStyle = FormBorderStyle.None;
			mPanel.Controls.Add(m_LRuleEditor);
			m_LRuleEditor.Show();
		}

		public bool RefreshRuleGrid(UltraGrid multraGridRule, IPcrExperimentProject mPcrExperimentProject)
		{
			if (m_LRuleEditor == null)
			{
				return false;
			}
			m_LRuleEditor.RefreshRuleGrid(mApplication, multraGridRule, mPcrExperimentProject);
			return true;
		}

		public bool SaveRuleGrid(UltraGrid multraGridRule, IPcrExperimentProject mPcrExperimentProject)
		{
			if (m_LRuleEditor == null)
			{
				return false;
			}
			if (!m_LRuleEditor.SaveRuleGrid(multraGridRule, mPcrExperimentProject.AdvancedRule))
			{
				return false;
			}
			return true;
		}

		public IRuleItem CreateRuleObject()
		{
			return new RuleItem();
		}

		public List<string> AnalysisRule(IPcrExperimentProject mPcrExperimentProject)
		{
			if (mPcrExperimentProject != null && mPcrExperimentProject.AdvancedRule != null)
			{
				ExpressionAnalysisResult(mPcrExperimentProject, mPcrExperimentProject.AdvancedRule);
				return RuleCmpAnalysis(mPcrExperimentProject, mPcrExperimentProject.AdvancedRule);
			}
			return null;
		}

		public List<string> RuleCmpAnalysis(IPcrExperimentProject mPcrExperimentProject, IRuleItem mRuleItem)
		{
			List<IPcrCell> cells = mPcrExperimentProject.Cells;
			List<string> list = new List<string>();
			bool flag = false;
			flag = mRuleItem.SelectTarget;
			foreach (IPcrCell item in cells)
			{
				string text = null;
				if (item.Project == null)
				{
					text = "";
					list.Add(text);
					continue;
				}
				for (int i = 0; i < item.Project.ChannelConfigurations.Length; i++)
				{
					item.SetCellInformation("InterpretationKey", i, string.Empty);
				}
				if (mRuleItem.RuleEditorList != null)
				{
					foreach (IRuleEditor ruleEditor in mRuleItem.RuleEditorList)
					{
						int num = 0;
						bool[] array = new bool[ruleEditor.ConditionEditorList.Count];
						foreach (IConditionEditor conditionEditor in ruleEditor.ConditionEditorList)
						{
							string[] array2 = null;
							if (conditionEditor.Condition == "")
							{
								array[num] = true;
								num++;
								continue;
							}
							if (conditionEditor.ExpressionIndex > 9)
							{
								string[] separator = new string[4] { "<", "<=", "=", "<>" };
								string[] array3 = conditionEditor.Condition.Split(separator, StringSplitOptions.RemoveEmptyEntries);
								string[] array4 = conditionEditor.Condition.Split(' ');
								array2 = ((conditionEditor.ExpressionIndex - 10 == 0) ? new string[3]
								{
									array3[0].Trim(),
									array4[array4.Length - 2],
									array4[array4.Length - 1]
								} : ((array4.Length > 3 && array3.Length > 2) ? new string[5]
								{
									array3[0].Trim(),
									array4[1],
									array3[1].Trim(),
									array4[array4.Length - 2],
									array4[array4.Length - 1]
								} : new string[3]
								{
									array3[0].Trim(),
									array4[1],
									array3[1].Trim()
								}));
							}
							else
							{
								string[] separator2 = new string[4] { "<", "<=", "=", "<>" };
								string[] array5 = conditionEditor.Condition.Split(separator2, StringSplitOptions.RemoveEmptyEntries);
								string[] array6 = conditionEditor.Condition.Split(' ');
								array2 = ((conditionEditor.ExpressionIndex == 0) ? new string[3]
								{
									array5[0].Trim(),
									array6[array6.Length - 2],
									array6[array6.Length - 1]
								} : ((array5.Length == 3 && array6.Length > 3 && array5[array5.Length - 1].Contains(array6[array6.Length - 1])) ? new string[5]
								{
									array5[0].Trim(),
									array6[1],
									array5[1].Trim(),
									array6[array6.Length - 2],
									array6[array6.Length - 1]
								} : new string[3]
								{
									array5[0].Trim(),
									array6[1],
									array5[1].Trim()
								}));
							}
							string[] array7 = null;
							if (conditionEditor.ExpressionIndex > 9)
							{
								array7 = array2[conditionEditor.ExpressionIndex - 10].Split(' ');
							}
							else
							{
								string text2 = array2[conditionEditor.ExpressionIndex];
								if (mRuleItem.ExpressionEditorList == null)
								{
									break;
								}
								foreach (IExressionEditor expressionEditor in mRuleItem.ExpressionEditorList)
								{
									if (expressionEditor.Expression_Name == text2)
									{
										array7 = expressionEditor.Expression_Content.Split(' ');
										break;
									}
								}
							}
							List<string> list2 = new List<string>();
							if (array7 == null)
							{
								break;
							}
							for (int j = 0; j < array7.Length - 1; j += 2)
							{
								if (array7[j].Contains("("))
								{
									string[] array8 = array7[j].Split('(', ')');
									list2.Add(j.ToString());
									list2.Add(array8[0]);
									list2.Add(array8[1]);
								}
							}
							if (array7[array7.Length - 1].Contains("("))
							{
								string[] array9 = array7[array7.Length - 1].Split('(', ')');
								list2.Add((array7.Length - 1).ToString());
								list2.Add(array9[0]);
								list2.Add(array9[1]);
							}
							string s = null;
							double result = 0.0;
							bool flag2 = false;
							bool flag3 = false;
							bool flag4 = false;
							int k = 0;
							string text3 = null;
							for (int l = 0; l < array7.Length; l++)
							{
								if (flag3)
								{
									break;
								}
								if (flag2 && l >= 2)
								{
									flag2 = false;
								}
								if (l % 2 == 0)
								{
									for (; k < list2.Count - 1; k += 2)
									{
										if (list2[k] == l.ToString())
										{
											bool flag5 = false;
											for (int m = 0; m < item.Project.ChannelConfigurations.Length; m++)
											{
												if (!item.Project.ChannelConfigurations[m].IsSelected || !item.Project.ChannelConfigurations[m].IsAvailable)
												{
													continue;
												}
												if (ruleEditor.RuleItemName == "")
												{
													flag5 = true;
												}
												else if (item.GetCellInformation("DetectionTypeKey", m) == ruleEditor.RuleItemName)
												{
													if (ruleEditor.RuleItemName == mConfigurationService.GetDetectionTypeArray(PcrSystemType.AbsoluteAnalysis)[1])
													{
														flag5 = true;
														break;
													}
													if (ruleEditor.RuleProperty == item.GetCellInformation("PropertyKey", m))
													{
														flag5 = true;
														break;
													}
												}
											}
											if (!flag5)
											{
												s = mResourceManager.GetString("NoResultString");
												flag4 = true;
											}
											else
											{
												bool flag6 = false;
												for (int n = 0; n < item.Project.ChannelConfigurations.Length; n++)
												{
													if (item.Project.ChannelConfigurations[n].IsSelected && item.Project.ChannelConfigurations[n].IsAvailable)
													{
														if (item.GetCellInformation("DetectionProjectKey", n) == list2[k + 2])
														{
															string text6 = list2[k + 2];
															if (list2[k + 1] == "Rn")
															{
																s = item.GetAmplificationLightDataArray(n)[item.GetAmplificationLightDataArray(n).Length - 1].ToString();
																flag4 = true;
																break;
															}
															if (list2[k + 1] == "Cn")
															{
																s = item.GetCellInformation("MeasurementResultKey", n);
																flag4 = true;
																break;
															}
															if (list2[k + 1] == "Ct")
															{
																s = item.GetCycleValue(n).ToString();
																double cycleValue = item.GetCycleValue(n);
																if (double.IsNaN(cycleValue))
																{
																	s = ((double)item.PcrExperiment.GetActualAmplificationDetectionCycle() + 0.1).ToString();
																}
																flag4 = true;
																break;
															}
														}
														if (item.MultiTubeCells.Count > 1)
														{
															for (int num2 = 0; num2 < item.MultiTubeCells.Count; num2++)
															{
																string cellInformation = item.MultiTubeCells[num2].GetCellInformation("DetectionProjectKey", n);
																if (!(cellInformation == list2[k + 2]))
																{
																	continue;
																}
																if (list2[k + 1] == "Rn")
																{
																	s = item.MultiTubeCells[num2].GetAmplificationLightDataArray(n)[item.MultiTubeCells[num2].GetAmplificationLightDataArray(n).Length - 1].ToString();
																	flag6 = true;
																	flag4 = true;
																	break;
																}
																if (list2[k + 1] == "Cn")
																{
																	s = item.MultiTubeCells[num2].GetCellInformation("MeasurementResultKey", n);
																	flag6 = true;
																	flag4 = true;
																	break;
																}
																if (list2[k + 1] == "Ct")
																{
																	s = item.MultiTubeCells[num2].GetCycleValue(n).ToString();
																	double cycleValue2 = item.MultiTubeCells[num2].GetCycleValue(n);
																	if (double.IsNaN(cycleValue2))
																	{
																		s = ((double)item.PcrExperiment.GetActualAmplificationDetectionCycle() + 0.1).ToString();
																	}
																	flag6 = true;
																	flag4 = true;
																	break;
																}
															}
														}
													}
													if (flag6)
													{
														break;
													}
												}
											}
											if (flag4)
											{
												k += 3;
												break;
											}
											continue;
										}
										s = array7[l];
										break;
									}
									if (k >= list2.Count && !flag4)
									{
										s = array7[l];
									}
									if (!double.TryParse(s, out result))
									{
										result = 0.0;
										flag3 = true;
									}
									string text4 = result.ToString();
									string[] array10 = text4.Split('E');
									if (array10.Length > 1)
									{
										int num3 = Convert.ToInt16(array10[1].TrimStart('-', '+'));
										StringBuilder stringBuilder = new StringBuilder(num3 + 6);
										stringBuilder.Append("{0:0.");
										for (int num4 = 0; num4 < num3; num4++)
										{
											stringBuilder.Append("#");
										}
										stringBuilder.Append("}");
										text3 += string.Format(stringBuilder.ToString(), result);
									}
									else
									{
										text3 += result;
									}
									flag4 = false;
									flag2 = true;
								}
								else
								{
									text3 += array7[l];
								}
							}
							if (flag3)
							{
								array[num] = false;
							}
							else
							{
								double result2 = 0.0;
								if (text3 == null)
								{
									result = 0.0;
								}
								else
								{
									string text5 = text3.Trim();
									if (text5 != "非数字")
									{
										if (!text5.Contains("."))
										{
											mCalculator.Expression = text5 + ".0";
										}
										else
										{
											mCalculator.Expression = text5;
										}
										string s2 = mCalculator.ExecuteToString();
										if (!double.TryParse(s2, out result))
										{
											result = 0.0;
										}
									}
									else
									{
										result = 0.0;
									}
								}
								if (array2.Length == 3)
								{
									if (conditionEditor.ExpressionIndex - 10 == 0)
									{
										if (double.TryParse(array2[2], out result2))
										{
											switch (array2[1])
											{
											case "<":
												if (result < result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											case "<=":
												if (result <= result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											case "=":
												if (result == result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											case "<>":
												if (result != result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											}
										}
									}
									else
									{
										if (double.TryParse(array2[2], out result2))
										{
											switch (array2[1])
											{
											case "<":
												if (result < result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											case "<=":
												if (result <= result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											case "=":
												if (result == result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											case "<>":
												if (result != result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											}
										}
										if (double.TryParse(array2[0], out result2))
										{
											switch (array2[1])
											{
											case "<":
												if (result > result2)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											case "<=":
												if (result2 <= result)
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
												break;
											}
										}
									}
								}
								else
								{
									if (double.TryParse(array2[4], out result2))
									{
										switch (array2[3])
										{
										case "<":
											if (result < result2)
											{
												array[num] = true;
											}
											else
											{
												array[num] = false;
											}
											break;
										case "<=":
											if (result <= result2)
											{
												array[num] = true;
											}
											else
											{
												array[num] = false;
											}
											break;
										case "=":
											if (result == result2)
											{
												array[num] = true;
											}
											else
											{
												array[num] = false;
											}
											break;
										case "<>":
											if (result != result2)
											{
												array[num] = true;
											}
											else
											{
												array[num] = false;
											}
											break;
										}
									}
									if (double.TryParse(array2[0], out result2))
									{
										switch (array2[1])
										{
										case "<":
											if (result > result2)
											{
												if (array[num])
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
											}
											else
											{
												array[num] = false;
											}
											break;
										case "<=":
											if (result2 <= result)
											{
												if (array[num])
												{
													array[num] = true;
												}
												else
												{
													array[num] = false;
												}
											}
											else
											{
												array[num] = false;
											}
											break;
										}
									}
								}
							}
							num++;
						}
						bool flag7 = true;
						mRuleItem.SelectTarget = true;
						if (ruleEditor.ConditionEditorList.Count > 0 && ruleEditor.ConditionEditorList[0].Condition != "" && ruleEditor.ConditionEditorList[0].ConditionIndex == 2)
						{
							flag7 = array[0];
						}
						for (int num5 = 1; num5 < ruleEditor.ConditionEditorList.Count; num5++)
						{
							if (ruleEditor.ConditionEditorList[num5].Condition != "" && ruleEditor.ConditionEditorList[num5 - 1].Connection != "")
							{
								if (ruleEditor.ConditionEditorList[num5 - 1].Connection == "AND")
								{
									flag7 = flag7 && array[num5];
								}
								if (ruleEditor.ConditionEditorList[num5 - 1].Connection == "OR")
								{
									flag7 = flag7 || array[num5];
								}
							}
							else if (ruleEditor.ConditionEditorList[num5].Condition != "")
							{
								flag7 = array[num5];
							}
						}
						if (!mRuleItem.SelectTarget)
						{
							text = ((!flag7) ? (text ?? "") : (text + ruleEditor.RuleInterpretation.TrimEnd("\n\r".ToCharArray()) + ";"));
						}
						else if (flag7)
						{
							for (int num6 = 0; num6 < item.Project.ChannelConfigurations.Length; num6++)
							{
								if (item.Project.ChannelConfigurations[num6].IsSelected && item.Project.ChannelConfigurations[num6].IsAvailable)
								{
									string cellInformation2 = item.GetCellInformation("InterpretationKey", num6);
									if (!string.IsNullOrEmpty(cellInformation2))
									{
										cellInformation2 = cellInformation2 + ";" + ruleEditor.RuleInterpretation.TrimEnd("\n\r".ToCharArray());
										item.SetCellInformation("InterpretationKey", num6, cellInformation2);
									}
									else
									{
										item.SetCellInformation("InterpretationKey", num6, ruleEditor.RuleInterpretation.TrimEnd("\n\r".ToCharArray()));
									}
								}
							}
						}
						if (!mRuleItem.SelectColor || !flag7)
						{
							continue;
						}
						for (int num7 = 0; num7 < item.Project.ChannelConfigurations.Length; num7++)
						{
							if (item.Project.ChannelConfigurations[num7].IsSelected && item.Project.ChannelConfigurations[num7].IsAvailable)
							{
								item.SetCellInformation("InterpretationColorKey", num7, ruleEditor.RuleColorName);
							}
						}
					}
					if (!mRuleItem.SelectTarget)
					{
						text = text.TrimEnd(';');
						list.Add(text);
					}
				}
				else if (!mRuleItem.SelectTarget)
				{
					text = "";
					list.Add(text);
				}
				if (mRuleItem.SelectTarget)
				{
					continue;
				}
				IProjectItem[] projectItems = mPcrExperimentProject.ProjectItems;
				foreach (IProjectItem projectItem in projectItems)
				{
					if (projectItem != null && projectItem.ChannelConfiguration.IsAvailable && projectItem.ChannelConfiguration.IsSelected)
					{
						item.SetCellInformation("InterpretationKey", projectItem.ChannelConfiguration.Position, text);
					}
				}
			}
			if (!mRuleItem.SelectTarget)
			{
				ReSetInterpretationString(cells);
			}
			mRuleItem.SelectTarget = flag;
			return list;
		}

		private void ReSetInterpretationString(List<IPcrCell> pcrCells)
		{
			List<IPcrCell> list = new List<IPcrCell>();
			foreach (IPcrCell pcrCell in pcrCells)
			{
				if (list.Contains(pcrCell) || pcrCell.MultiTubeCells == null || pcrCell.MultiTubeCells.Count <= 0)
				{
					continue;
				}
				string text = string.Empty;
				int num = 0;
				if (pcrCell.Project != null)
				{
					IProjectItem[] projectItems = pcrCell.Project.ProjectItems;
					foreach (IProjectItem projectItem in projectItems)
					{
						if (projectItem != null && projectItem.ChannelConfiguration.IsAvailable && projectItem.ChannelConfiguration.IsSelected)
						{
							num++;
							if (string.IsNullOrEmpty(text))
							{
								text = pcrCell.GetCellInformation("InterpretationKey", projectItem.ChannelConfiguration.Position);
							}
						}
					}
				}
				if (string.IsNullOrEmpty(text))
				{
					continue;
				}
				string[] array = text.Split(new string[1] { ";" }, StringSplitOptions.None);
				if (array.Length <= 1)
				{
					continue;
				}
				int num2 = pcrCell.MultiTubeCells.Count * num;
				int num3 = array.Length / num2 + 1;
				int num4 = 0;
				foreach (IPcrCell multiTubeCell in pcrCell.MultiTubeCells)
				{
					list.Add(multiTubeCell);
					IProjectItem[] projectItems2 = pcrCell.Project.ProjectItems;
					foreach (IProjectItem projectItem2 in projectItems2)
					{
						if (projectItem2 == null || !projectItem2.ChannelConfiguration.IsAvailable || !projectItem2.ChannelConfiguration.IsSelected)
						{
							continue;
						}
						string text2 = string.Empty;
						for (int k = 0; k < num3; k++)
						{
							if (num4 < array.Length)
							{
								text2 = text2 + array[num4++] + ";";
							}
						}
						if (!string.IsNullOrEmpty(text2))
						{
							text2 = text2.TrimEnd(';');
						}
						multiTubeCell.SetCellInformation("InterpretationKey", projectItem2.ChannelConfiguration.Position, text2);
					}
				}
			}
		}

		public Dictionary<string, string[]> ExpressionAnalysisResult(IPcrExperimentProject mPcrExperimentProject, IRuleItem mRuleItem)
		{
			Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>();
			List<IPcrCell> cells = mPcrExperimentProject.Cells;
			bool flag = false;
			if (mRuleItem.ExpressionAnalysis != null)
			{
				foreach (string key in mRuleItem.ExpressionAnalysis.Keys)
				{
					string[] array = mRuleItem.ExpressionAnalysis[key];
					string[] array2 = new string[array.Length];
					flag = false;
					for (int i = 0; i < array.Length; i++)
					{
						if (array[i] == null)
						{
							continue;
						}
						string text = null;
						string[] array3 = null;
						for (int j = 0; j < mRuleItem.ExpressionEditorList.Count; j++)
						{
							if (array[i] == mRuleItem.ExpressionEditorList[j].Expression_Name)
							{
								text = mRuleItem.ExpressionEditorList[j].Expression_Content;
								break;
							}
						}
						if (text == null)
						{
							array2[i] = null;
							continue;
						}
						array3 = text.Split(' ');
						if (array3 == null)
						{
							array2[i] = null;
							continue;
						}
						List<string> list = new List<string>();
						for (int k = 0; k < array3.Length - 1; k += 2)
						{
							if (array3[k].Contains("("))
							{
								string[] array4 = array3[k].Split('(', ')');
								list.Add(k.ToString());
								list.Add(array4[0]);
								list.Add(array4[1]);
							}
						}
						if (array3[array3.Length - 1].Contains("("))
						{
							string[] array5 = array3[array3.Length - 1].Split('(', ')');
							list.Add((array3.Length - 1).ToString());
							list.Add(array5[0]);
							list.Add(array5[1]);
						}
						bool flag2 = false;
						foreach (IPcrCell item in cells)
						{
							flag2 = false;
							flag = false;
							if (item.Project == null)
							{
								continue;
							}
							IProjectItem[] projectItems = item.Project.ProjectItems;
							foreach (IProjectItem projectItem in projectItems)
							{
								if (projectItem != null && projectItem.ChannelConfiguration.IsAvailable && projectItem.ChannelConfiguration.IsSelected && projectItem.Name.Contains(key))
								{
									string s = null;
									double result = 0.0;
									bool flag3 = false;
									bool flag4 = false;
									bool flag5 = false;
									int m = 0;
									string text2 = null;
									for (int n = 0; n < array3.Length; n++)
									{
										if (flag4)
										{
											break;
										}
										if (flag3 && n >= 2)
										{
											flag3 = false;
										}
										if (n % 2 == 0)
										{
											for (; m < list.Count - 1; m += 2)
											{
												if (list[m] == n.ToString())
												{
													bool flag6 = false;
													for (int num = 0; num < item.Project.ChannelConfigurations.Length; num++)
													{
														if (item.Project.ChannelConfigurations[num].IsSelected && item.Project.ChannelConfigurations[num].IsAvailable)
														{
															if (item.GetCellInformation("DetectionProjectKey", num) == list[m + 2])
															{
																if (list[m + 1] == "Rn")
																{
																	s = item.GetAmplificationLightDataArray(num)[item.GetAmplificationLightDataArray(num).Length - 1].ToString();
																	flag5 = true;
																	break;
																}
																if (list[m + 1] == "Cn")
																{
																	s = item.GetCellInformation("MeasurementResultKey", num);
																	flag5 = true;
																	break;
																}
																if (list[m + 1] == "Ct")
																{
																	s = item.GetCycleValue(num).ToString();
																	double cycleValue = item.GetCycleValue(num);
																	if (double.IsNaN(cycleValue))
																	{
																		s = ((double)item.PcrExperiment.GetActualAmplificationDetectionCycle() + 0.1).ToString();
																	}
																	flag5 = true;
																	break;
																}
															}
															if (item.MultiTubeCells.Count > 1)
															{
																for (int num2 = 0; num2 < item.MultiTubeCells.Count; num2++)
																{
																	string cellInformation = item.MultiTubeCells[num2].GetCellInformation("DetectionProjectKey", num);
																	if (!(cellInformation == list[m + 2]))
																	{
																		continue;
																	}
																	if (list[m + 1] == "Rn")
																	{
																		s = item.MultiTubeCells[num2].GetAmplificationLightDataArray(num)[item.MultiTubeCells[num2].GetAmplificationLightDataArray(num).Length - 1].ToString();
																		flag6 = true;
																		flag5 = true;
																		break;
																	}
																	if (list[m + 1] == "Cn")
																	{
																		s = item.MultiTubeCells[num2].GetCellInformation("MeasurementResultKey", num);
																		flag6 = true;
																		flag5 = true;
																		break;
																	}
																	if (list[m + 1] == "Ct")
																	{
																		s = item.MultiTubeCells[num2].GetCycleValue(num).ToString();
																		double cycleValue2 = item.MultiTubeCells[num2].GetCycleValue(num);
																		if (double.IsNaN(cycleValue2))
																		{
																			s = ((double)item.PcrExperiment.GetActualAmplificationDetectionCycle() + 0.1).ToString();
																		}
																		flag6 = true;
																		flag5 = true;
																		break;
																	}
																}
															}
														}
														if (flag6)
														{
															break;
														}
													}
													if (flag5)
													{
														m += 3;
														break;
													}
													continue;
												}
												s = array3[n];
												break;
											}
											if (m >= list.Count && !flag5)
											{
												s = array3[n];
											}
											if (!double.TryParse(s, out result))
											{
												result = 0.0;
												flag4 = true;
											}
											string text3 = result.ToString();
											string[] array6 = text3.Split('E');
											if (array6.Length > 1)
											{
												int num3 = Convert.ToInt16(array6[1].TrimStart('-', '+'));
												StringBuilder stringBuilder = new StringBuilder(num3 + 6);
												stringBuilder.Append("{0:0.");
												for (int num4 = 0; num4 < num3; num4++)
												{
													stringBuilder.Append("#");
												}
												stringBuilder.Append("}");
												text2 += string.Format(stringBuilder.ToString(), result);
											}
											else
											{
												text2 += result;
											}
											flag5 = false;
											flag3 = true;
										}
										else
										{
											text2 += array3[n];
										}
									}
									if (flag4)
									{
										array2[i] = null;
										flag2 = true;
									}
									else if (text2 == null)
									{
										array2[i] = null;
										flag2 = true;
									}
									else
									{
										string text4 = text2.Trim();
										if (text4 != "非数字")
										{
											mCalculator.Expression = text4;
											string s2 = mCalculator.ExecuteToString();
											if (!double.TryParse(s2, out result))
											{
												array2[i] = null;
												flag2 = true;
											}
											else
											{
												array2[i] = result.ToString("0.00");
												flag2 = true;
											}
										}
										else
										{
											array2[i] = null;
											flag2 = true;
										}
									}
								}
								if (flag2)
								{
									break;
								}
							}
							if (!flag2)
							{
								continue;
							}
							for (int num5 = 0; num5 < item.Project.ChannelConfigurations.Length; num5++)
							{
								if (!item.Project.ChannelConfigurations[num5].IsSelected || !item.Project.ChannelConfigurations[num5].IsAvailable)
								{
									continue;
								}
								if (item.GetCellInformation("DetectionProjectKey", num5) == key)
								{
									if (!flag)
									{
										item.SetRuleCalculationValueCount(num5, array.Length);
										flag = true;
									}
									string text5 = (i + 1).ToString();
									item.SetCellInformation("RuleCalculationKey" + text5, num5, array2[i]);
									break;
								}
								if (item.MultiTubeCells.Count <= 1)
								{
									continue;
								}
								for (int num6 = 0; num6 < item.MultiTubeCells.Count; num6++)
								{
									string cellInformation2 = item.MultiTubeCells[num6].GetCellInformation("DetectionProjectKey", num5);
									if (cellInformation2 == key)
									{
										if (!flag)
										{
											item.MultiTubeCells[num6].SetRuleCalculationValueCount(num6, array.Length);
											flag = true;
										}
										string text6 = (i + 1).ToString();
										item.MultiTubeCells[num6].SetCellInformation("RuleCalculationKey" + text6, num6, array2[i]);
										break;
									}
								}
							}
						}
					}
					dictionary.Add(key, array2);
				}
			}
			return dictionary;
		}
	}
}
